using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyBoss2Bullet : EnemyBaseFixed
{
    private Sprite smallBulletSprite;
    private Sprite bulletSprite;
    private SeqAction workAction=new(){};
    private Vector2 targetPosition;
    void Awake()
    {
        base.Init();
        smallBulletSprite=ResourcesPool.Sprites["魂-第二关-Boss-弹-小"];
        bulletSprite=ResourcesPool.Sprites["魂-第二关-Boss-弹"];
        mainSR.sprite=smallBulletSprite;
        collider2D.enabled=false;
    }

    void Start()
    {
        Run();
    }

    void FixedUpdate()
    {
        base.CommonFixedUpdate();
    }
    protected void UpdateStateNone(bool stateChanged, EnumState inState, out EnumState outState)
    {
        outState=EnumState.Working;
    }
    protected void UpdateStateWorking(bool stateChanged, EnumState inState, out EnumState outState)
    {
        outState=inState;
        if(stateChanged){
            Utility.GetNearestPlayerPosition(transform.position,out targetPosition);
            Vector2 position=transform.position;
            rig.velocity=(targetPosition-position).normalized*5f;
        }
        workAction.Update((SeqAction seq)=>{
            if(seq.DurationTime<0.2f){
                mainSR.sprite=smallBulletSprite;
                collider2D.enabled=false;
            }else{
                mainSR.sprite=bulletSprite;
                collider2D.enabled=true;
            }
        });
    }

    protected override void UpdateStateDie(bool stateChanged, EnumState inState, out EnumState outState)
    {
        base.UpdateStateDie(stateChanged, inState, out outState);
        Instantiate(Constant.Prefabs.EnemyBoom1.Load(),transform.position,Quaternion.identity);
        Destroy(gameObject);
    }
}
